using System;
using System.ComponentModel;

namespace CommonCore.Extensions
{
    public static class DataBinding
    {
       /// <summary>
       /// Raises the specified PropertyChangedEventHander
       /// </summary>
       /// <param name="propertyChangedEventHandler">The handler to invoke</param>
       /// <param name="sender">The sender</param>
       /// <param name="propertyName">The property name</param>
       public static void Raise(this PropertyChangedEventHandler propertyChangedEventHandler, object sender, string propertyName)
       {
           if (propertyChangedEventHandler == null) throw new ArgumentNullException("propertyChangedEventHandler");
           if (String.IsNullOrEmpty(propertyName)) throw new ArgumentNullException("propertyName");
           propertyChangedEventHandler(sender, new PropertyChangedEventArgs(propertyName));
       } 

       /// <summary>
       /// Raises the specified PropertyChangedEventHander on the UI Thread
       /// </summary>
       /// <param name="propertyChangedEventHandler">The handler to invoke</param>
       /// <param name="sender">The sender</param>
       /// <param name="propertyName">The property name</param>
       public static void RaiseOnUIThread(this PropertyChangedEventHandler propertyChangedEventHandler, object sender, string propertyName)
       {
           if (propertyChangedEventHandler == null) throw new ArgumentNullException("propertyChangedEventHandler");
           if (String.IsNullOrEmpty(propertyName)) throw new ArgumentNullException("propertyName");
           new Action<object, PropertyChangedEventArgs>(propertyChangedEventHandler).InvokeOnUIThread(sender, new PropertyChangedEventArgs(propertyName));
       } 

    }
}